namespace Cinema.Model.EF.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class relationshipsdefined : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.Actors", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.Genres", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.MovieTypes", "Movie_Id", "dbo.Movies");
            DropIndex("dbo.Actors", new[] { "Movie_Id" });
            DropIndex("dbo.Genres", new[] { "Movie_Id" });
            DropIndex("dbo.MovieTypes", new[] { "Movie_Id" });
            CreateTable(
                "dbo.Projections",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Date = c.DateTime(nullable: false),
                        Quality = c.Int(nullable: false),
                        Room_Id = c.Int(nullable: false),
                        Movie_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Rooms", t => t.Room_Id, cascadeDelete: true)
                .ForeignKey("dbo.Movies", t => t.Movie_Id, cascadeDelete: true)
                .Index(t => t.Room_Id)
                .Index(t => t.Movie_Id);
            
            CreateTable(
                "dbo.Reservations",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        NoOfPlaces = c.Int(nullable: false),
                        Status = c.Int(nullable: false),
                        Projection_Id = c.Int(),
                        User_Id = c.Int(nullable: false),
                        Projection_Id1 = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Projections", t => t.Projection_Id)
                .ForeignKey("dbo.Users", t => t.User_Id, cascadeDelete: true)
                .ForeignKey("dbo.Projections", t => t.Projection_Id1, cascadeDelete: true)
                .Index(t => t.Projection_Id)
                .Index(t => t.User_Id)
                .Index(t => t.Projection_Id1);
            
            CreateTable(
                "dbo.Rooms",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        NoOfPlaces = c.Int(nullable: false),
                        Name = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.MovieActors",
                c => new
                    {
                        Movie_Id = c.Int(nullable: false),
                        Actor_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Movie_Id, t.Actor_Id })
                .ForeignKey("dbo.Movies", t => t.Movie_Id, cascadeDelete: true)
                .ForeignKey("dbo.Actors", t => t.Actor_Id, cascadeDelete: true)
                .Index(t => t.Movie_Id)
                .Index(t => t.Actor_Id);
            
            CreateTable(
                "dbo.MovieGenres",
                c => new
                    {
                        Movie_Id = c.Int(nullable: false),
                        Genre_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Movie_Id, t.Genre_Id })
                .ForeignKey("dbo.Movies", t => t.Movie_Id, cascadeDelete: true)
                .ForeignKey("dbo.Genres", t => t.Genre_Id, cascadeDelete: true)
                .Index(t => t.Movie_Id)
                .Index(t => t.Genre_Id);
            
            CreateTable(
                "dbo.MovieMovieTypes",
                c => new
                    {
                        Movie_Id = c.Int(nullable: false),
                        MovieType_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Movie_Id, t.MovieType_Id })
                .ForeignKey("dbo.Movies", t => t.Movie_Id, cascadeDelete: true)
                .ForeignKey("dbo.MovieTypes", t => t.MovieType_Id, cascadeDelete: true)
                .Index(t => t.Movie_Id)
                .Index(t => t.MovieType_Id);
            
            AlterColumn("dbo.Genres", "Name", c => c.String(nullable: false, maxLength: 25));
            DropColumn("dbo.Actors", "Movie_Id");
            DropColumn("dbo.Genres", "Movie_Id");
            DropColumn("dbo.MovieTypes", "Movie_Id");
        }
        
        public override void Down()
        {
            AddColumn("dbo.MovieTypes", "Movie_Id", c => c.Int());
            AddColumn("dbo.Genres", "Movie_Id", c => c.Int());
            AddColumn("dbo.Actors", "Movie_Id", c => c.Int());
            DropForeignKey("dbo.MovieMovieTypes", "MovieType_Id", "dbo.MovieTypes");
            DropForeignKey("dbo.MovieMovieTypes", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.Projections", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.Projections", "Room_Id", "dbo.Rooms");
            DropForeignKey("dbo.Reservations", "Projection_Id1", "dbo.Projections");
            DropForeignKey("dbo.Reservations", "User_Id", "dbo.Users");
            DropForeignKey("dbo.Reservations", "Projection_Id", "dbo.Projections");
            DropForeignKey("dbo.MovieGenres", "Genre_Id", "dbo.Genres");
            DropForeignKey("dbo.MovieGenres", "Movie_Id", "dbo.Movies");
            DropForeignKey("dbo.MovieActors", "Actor_Id", "dbo.Actors");
            DropForeignKey("dbo.MovieActors", "Movie_Id", "dbo.Movies");
            DropIndex("dbo.MovieMovieTypes", new[] { "MovieType_Id" });
            DropIndex("dbo.MovieMovieTypes", new[] { "Movie_Id" });
            DropIndex("dbo.MovieGenres", new[] { "Genre_Id" });
            DropIndex("dbo.MovieGenres", new[] { "Movie_Id" });
            DropIndex("dbo.MovieActors", new[] { "Actor_Id" });
            DropIndex("dbo.MovieActors", new[] { "Movie_Id" });
            DropIndex("dbo.Reservations", new[] { "Projection_Id1" });
            DropIndex("dbo.Reservations", new[] { "User_Id" });
            DropIndex("dbo.Reservations", new[] { "Projection_Id" });
            DropIndex("dbo.Projections", new[] { "Movie_Id" });
            DropIndex("dbo.Projections", new[] { "Room_Id" });
            AlterColumn("dbo.Genres", "Name", c => c.String());
            DropTable("dbo.MovieMovieTypes");
            DropTable("dbo.MovieGenres");
            DropTable("dbo.MovieActors");
            DropTable("dbo.Rooms");
            DropTable("dbo.Reservations");
            DropTable("dbo.Projections");
            CreateIndex("dbo.MovieTypes", "Movie_Id");
            CreateIndex("dbo.Genres", "Movie_Id");
            CreateIndex("dbo.Actors", "Movie_Id");
            AddForeignKey("dbo.MovieTypes", "Movie_Id", "dbo.Movies", "Id");
            AddForeignKey("dbo.Genres", "Movie_Id", "dbo.Movies", "Id");
            AddForeignKey("dbo.Actors", "Movie_Id", "dbo.Movies", "Id");
        }
    }
}
